<template>
  <div class="ranking-list-container">
    <el-scrollbar>
      <table class="ranking-table">
        <thead>
        <tr style="font-size: 12px">
          <th style="background-color: #f0f8ff;">序号</th>
          <th style="background-color: #f0f8ff;">年度</th>
          <th style="background-color: #f0f8ff;">项目名称</th>
          <th style="background-color: #f0f8ff;">项目编号</th>
          <th style="background-color: #f0f8ff;">材料费用</th>
          <th style="background-color: #f0f8ff;">研发活动记录</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item, index) in rankingList" :key="index">
          <td>{{ index + 1 }}</td>
          <td>{{ item.year }}</td>
          <td :data-full-text="item.projectName" :title="item.projectName">{{ item.projectName }}</td>
          <td>{{ item.projectNumber }}</td>
          <td>{{ item.materialCost }}</td>
          <td><a href="#" @click.prevent="viewDetails(item)">查看</a></td>
        </tr>
        </tbody>
      </table>
    </el-scrollbar>
  </div>
</template>

<script>
export default {
  name: "RankingList",
  data() {
    return {
      rankingList: [
        { year: "2025", projectName: "银江水电站复杂水流条件下二三期导截流...", projectNumber: "2025-05-003", materialCost: 0 },
        { year: "2024", projectName: "风电项目基础施工技术研究", projectNumber: "2024-06-017", materialCost: 426216.3 },
        { year: "2024", projectName: "港口工业厂房及其机电设备技术研究", projectNumber: "2024-07-003", materialCost: 4573773.3025689 },
        { year: "2024", projectName: "上跨既有线的转体桥梁智能建造关键技术...", projectNumber: "2024-02-005", materialCost: 743027.44 },
        { year: "2024", projectName: "双碳背景下全断面砂砾岩地层土压平衡盾...", projectNumber: "2024-02-006", materialCost: 0 },
        { year: "2024", projectName: "大面积斜坡建基面衬砌快速施工工艺研究", projectNumber: "2024-07-006", materialCost: 0 },
        { year: "2024", projectName: "绿线轻轨大桥 CFA 联排桩施工技术研究", projectNumber: "2024-07-001", materialCost: 2453753.16 },
        { year: "2024", projectName: "水下淘蚀区混凝土施工技术研究", projectNumber: "2024-04-001", materialCost: 284221.29 },
        { year: "2024", projectName: "面板堆石坝快速筑坝施工技术研究", projectNumber: "2024-01-023", materialCost: 0 },
        { year: "2024", projectName: "大体积堆石混凝土重力坝施工关键技术研究", projectNumber: "2024-01-019", materialCost: 344558.36 }
      ],
    };
  },
  methods: {
    viewDetails(item) {
      // Implement the logic to view details here
      console.log(`Viewing details for project: ${item.projectName}`);
    },
  },
};
</script>

<style scoped>
.ranking-list-container {
  height: 350px;
  overflow-y: auto;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; /* 使用固定布局 */
}

.ranking-table th,
.ranking-table td {
  padding: 8px;
  text-align: center;
  border-bottom: 1px solid #ebebeb;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis; /* 当内容超出容器宽度时显示为省略号 */
  max-width: 0; /* 强制文本溢出 */
  position: relative; /* 使绝对定位的子元素相对于此元素定位 */
}

/* 当鼠标悬停在单元格上时 */
.ranking-table td:hover::after {
  content: attr(data-full-text); /* 显示完整文本 */
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  white-space: normal; /* 允许换行 */
  width: 200px; /* 提示框宽度 */
  background-color: #333;
  color: #fff;
  padding: 5px;
  border-radius: 4px;
  z-index: 10;
}

/* 设置列宽 */
.ranking-table th:first-child,
.ranking-table td:first-child {
  width: 5%; /* 序号占总宽度的5% */
}
.ranking-table th:nth-child(2),
.ranking-table td:nth-child(2) {
  width: 10%; /* 年度占总宽度的5% */
}
.ranking-table th:nth-child(3),
.ranking-table td:nth-child(3) {
  width: 30%; /* 项目名称占总宽度的30% */
}
.ranking-table th:nth-child(4),
.ranking-table td:nth-child(4) {
  width: 15%; /* 项目编号占总宽度的15% */
}
.ranking-table th:nth-child(5),
.ranking-table td:nth-child(5) {
  width: 15%; /* 材料费用占总宽度的15% */
}
.ranking-table th:nth-child(6),
.ranking-table td:nth-child(6) {
  width: 10%; /* 研发活动记录占总宽度的10% */
}

/* 自定义滚动条样式 */
::-webkit-scrollbar {
  width: 3px; /* 滚动条宽度 */
  background-color: transparent;
}

::-webkit-scrollbar-track {
  border-radius: 4px;
  background-color: #dddddd; /* 轨道颜色 */
}

::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: #5bc0de; /* 滑块颜色 */
  transition: background-color 0.3s ease-in-out;
}

/* 响应式设计 */
@media screen and (min-width: 2801px) and (max-width: 2900px) {
  .ranking-list-container {
    height: 590px;
  }
}
@media screen and (min-width: 2701px) and (max-width: 2800px) {
  .ranking-list-container {
    height: 575px;
  }
}
</style>
